using System;
using System.Drawing;
using System.Xml.Serialization;
using System.IO;

namespace UTE.Serializer
{
	/// <summary>
	/// Summary description for Class1.
	/// </summary>
	public class BMPXMLSerialization
	{
		public int Width;
		public int Height;
		private Bitmap bitmapObject;

		//XmlSerializer can only serialize classes that have default constructor
		public BMPXMLSerialization()
		{
			bitmapObject = null;
		}

		public BMPXMLSerialization(Bitmap bmpToSerialize)
		{
			bitmapObject = bmpToSerialize;
			Width = bmpToSerialize.Width;
			Height = bmpToSerialize.Height;
		}

		public byte[] BMPBytes
		{
			get
			{
				MemoryStream memStream = new MemoryStream();
				bitmapObject.Save(memStream, System.Drawing.Imaging.ImageFormat.Gif);
				int ImageSize = Convert.ToInt32(memStream.Length);
				byte[] ImageBytes = new byte[ImageSize];
				memStream.Position=0;
				memStream.Read(ImageBytes, 0, ImageSize);
				memStream.Close();
				return ImageBytes;
			}

			set
			{
				bitmapObject = new Bitmap(new MemoryStream(value));
			}
		}
		[XmlIgnore]
		public Bitmap Bitmap
		{
			get
			{
				return bitmapObject;
			}
		}
	}
}
